#pragma once
#include "glutwindow.h"
#include <gl/glew.h>
#include <gl/glut.h>
#include "glinfo.h"
#include <Cg/cg.h>
#include <Cg/cgGL.h>
#include "FluidSolver.h"

class CSmokeBoxWin :
	public cwc::glutWindow
{
public:
	CSmokeBoxWin(int w, int h);
	~CSmokeBoxWin(void);
	virtual void	OnInit(void);
	virtual	void	OnRender(void);
	virtual	void	OnIdle(void);							//process during idle, compute next time step smoke situation here
	virtual	void	OnPreDisplay();								//initialize before render, called only once
	virtual	void	OnResize(int nWidth, int nHeight);
	virtual	void	OnClose();
	virtual	void	OnMouseDown(int button, int x, int y);
	virtual void	OnMouseUp(int button, int x, int y);
	virtual	void	OnMouseMove(int x, int y, int mod);
	virtual	void	OnKeyDown(int nKey, char cAscii);
	virtual	void	OnKeyUp(int nKey, char cAscii);

protected:
	//multi target rendering
	void			InitFrameBuffer(void);
	void			InitCgFX(void);
	void			CheckforCgError(const char* situation);
	void			UseSamplerParameter(CGeffect effect, const char *paramName, GLuint texobj);

	void			UpdateIntersTex(void);
	void			drawBoundingBox(float hx, float hy, float hz, float offset);

protected:
	//fluid simulation
	CFluidSolver	*m_pFluidSolver;
	int				m_gridN;
	float			m_timeStep, m_fluidDiff, m_fluidVisc, m_fluidSource;
	float			m_hx, m_hy, m_hz;		//dimensions of bounding box
	float			m_hc, m_offset;					//dimensions of a cell


	//camera info
	int				m_winWidth, m_winHeight;
	float			m_boundLeft, m_boundRight, m_boundTop, m_boundBottom, m_boundNear, m_boundFar;
	float			m_eye[3];
	float			m_rot[3];
	int				m_oldX, m_oldY;
	int				m_button;
	bool			m_isUpdated;			//matrix of the camera was changed

	unsigned int	m_fbo_texture, m_fbo, m_rbo, m_smoketexture;
	char			m_programName[100];

	//Cg variables
	CGcontext		m_cgContext;
	CGeffect		m_cgEffect;
	CGtechnique		m_cgTechnique;
	CGparameter		m_cgModelViewProjParam;
	CGparameter		m_cgModelViewParam;
	CGparameter		m_cgModelViewInvParam;
	CGparameter		m_cgIntersTexParam;
	CGparameter		m_cgSmokeTexParam;
	CGparameter		m_cgCellDim, m_cgGridDim;
	//glinfo
	cwc::glInfo		m_glInfo;
};
